home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / menininh.swf / scripts / __Packages / Point2D.as < prev    next >
Encoding:
Text File  |  2007-07-06  |  1.5 KB  |  64 lines

  1. class Point2D
  2. {
  3.    var x = 0;
  4.    var y = 0;
  5.    var rotation = 0;
  6.    function Point2D(sx, sy, srot)
  7.    {
  8.       this.x = sx;
  9.       this.y = sy;
  10.       this.rotation = srot;
  11.    }
  12.    static function polar(len, angle)
  13.    {
  14.       var _loc1_ = new Point2D();
  15.       _loc1_.x = len * Math.cos(angle);
  16.       _loc1_.y = len * Math.sin(angle);
  17.       return _loc1_;
  18.    }
  19.    function clone()
  20.    {
  21.       var _loc2_ = new Point2D(this.x,this.y,this.rotation);
  22.       return _loc2_;
  23.    }
  24.    function dotProduct(op)
  25.    {
  26.       return this.x * op.x + this.y * op.y;
  27.    }
  28.    function normalize()
  29.    {
  30.       if(Math.abs(this.x) > Math.abs(this.y))
  31.       {
  32.          this.y /= Math.abs(this.x);
  33.          this.x /= Math.abs(this.x);
  34.       }
  35.       else
  36.       {
  37.          this.x /= Math.abs(this.y);
  38.          this.y /= Math.abs(this.y);
  39.       }
  40.    }
  41.    function subtract(p)
  42.    {
  43.       var _loc2_ = new Point2D(this.x - p.x,this.y - p.y,this.rotation - p.rotation);
  44.       return _loc2_;
  45.    }
  46.    function multiply(factor)
  47.    {
  48.       return new Point2D(this.x * factor,this.y * factor,this.rotation);
  49.    }
  50.    function getLength()
  51.    {
  52.       var _loc2_ = new Point2D(Math.abs(this.x),Math.abs(this.y));
  53.       return Math.sqrt(this.x * this.x + this.y * this.y);
  54.    }
  55.    function toString()
  56.    {
  57.       return "(" + this.x + "," + this.y + ")";
  58.    }
  59.    function getDirection()
  60.    {
  61.       return Math.atan2(this.x,- this.y) / 3.141592653589793 * 180;
  62.    }
  63. }
  64.